package com.generator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
/**
 * myBatis 自动生成 dao层文件
 */
public class GeneratorSqlmap {

	private void generator() throws Exception{
        List<String> warnings = new ArrayList<String>();
        //读取mybatis generator文件配置
        String classPath = this.getClass().getResource("/").getPath();
        File configFile = new File(classPath + "generator-config.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
	
	public static void main(String[] args) {
		try {
            System.out.println("===================== 开始！=====================");
            new GeneratorSqlmap().generator();
            System.out.println("===================== 完成！=====================");
        }catch (Exception e) {
            e.printStackTrace();
        }
	}
}
